Leadtools.WinForms Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
LoadThumbnails(Generic IEnumerable,String,RasterThumbnailBrowserLoadFlags) Method
See Also  Example
Leadtools.WinForms Namespace > RasterThumbnailBrowser Class > LoadThumbnails Method : LoadThumbnails(Generic IEnumerable,String,RasterThumbnailBrowserLoadFlags) Method



paths
The paths to browse. This can be a directories and files.
searchPattern
The search string to match against the names of files in path. The parameter cannot end in two periods ("..") or contain two periods ("..") followed by DirectorySeparatorChar or AltDirectorySeparatorChar, nor can it contain any of the characters in InvalidPathChars.
flags
An RasterThumbnailBrowserLoadFlags enumeration that can be a combination of the following:
ValueDescription
RasterThumbnailBrowserLoadFlags.NoneDefault mode, the method will return immediatly and the thumbnails are loaded in a background thread.
RasterThumbnailBrowserLoadFlags.BlockThe method will not return until all thumbnails are loaded.
RasterThumbnailBrowserLoadFlags.OnlyValidImageFilesOnly valid image files are loaded. Any file that contains data not recognized by the RasterThumbnailBrowser.Codecs object as a valid image file will not be loaded.
Browses the specified paths for supported images, and generates thumbnails for each image file that is found.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub LoadThumbnails( _
   ByVal paths As IEnumerable(Of String), _
   ByVal searchPattern As String, _
   ByVal flags As RasterThumbnailBrowserLoadFlags _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterThumbnailBrowser
Dim paths As IEnumerable(Of String)
Dim searchPattern As String
Dim flags As RasterThumbnailBrowserLoadFlags
 
instance.LoadThumbnails(paths, searchPattern, flags)
C# 
public void LoadThumbnails( 
   IEnumerable<string> paths,
   string searchPattern,
   RasterThumbnailBrowserLoadFlags flags
)
C++/CLI 
public:
void LoadThumbnails( 
   IEnumerable<String>^ paths,
   String^ searchPattern,
   RasterThumbnailBrowserLoadFlags flags
) 

Parameters

paths
The paths to browse. This can be a directories and files.
searchPattern
The search string to match against the names of files in path. The parameter cannot end in two periods ("..") or contain two periods ("..") followed by DirectorySeparatorChar or AltDirectorySeparatorChar, nor can it contain any of the characters in InvalidPathChars.
flags
An RasterThumbnailBrowserLoadFlags enumeration that can be a combination of the following:
ValueDescription
RasterThumbnailBrowserLoadFlags.NoneDefault mode, the method will return immediatly and the thumbnails are loaded in a background thread.
RasterThumbnailBrowserLoadFlags.BlockThe method will not return until all thumbnails are loaded.
RasterThumbnailBrowserLoadFlags.OnlyValidImageFilesOnly valid image files are loaded. Any file that contains data not recognized by the RasterThumbnailBrowser.Codecs object as a valid image file will not be loaded.

Example

This example will load two files and expands the multipage one.

Visual BasicCopy Code
Private Class MyForm2 : Inherits Form
   Public theBrowser As RasterThumbnailBrowser
   Public cancelOperation As Boolean ' Informs us if the user canceled the operation
   Public buttonCancel As Button ' Cancel browse loading
   Public buttonBrowse As Button ' Diplays the browse control
   Public progressBar As ProgressBar ' shows progress of loading browse images
   Private Sub buttonBrowse_Click(ByVal sender As Object, ByVal e As EventArgs)
      ' If we are already loading thumbails, cancel
      ' this operation
      If theBrowser.IsLoadingThumbnails Then
         theBrowser.CancelLoadingThumbnails()
      End If

      ' Clean all the items
      theBrowser.Items.Clear()

      ' Update the application state
      buttonCancel.Enabled = True
      progressBar.Value = 0

      ' And load the new thumbnails
      cancelOperation = False

      Dim folderPath As String = LeadtoolsExamples.Common.ImagesPath.Path
      Dim files As String() = New String(1) {folderPath & "\image1.jpx", folderPath}
      theBrowser.LoadThumbnails(files, "*.jpg", RasterThumbnailBrowserLoadFlags.Block Or RasterThumbnailBrowserLoadFlags.ExpandMultiPageFile)
   End Sub

   Private Sub thumbnailBrowser_LoadThumbnail(ByVal sender As Object, ByVal e As RasterThumbnailBrowserLoadThumbnailEventArgs)
      ' If this is the first iteration, update the progress bar minimum and maximum values
      If e.Index = 0 Then
         progressBar.Minimum = 0
         progressBar.Maximum = e.Total - 1
      End If

      ' Update where we are in the loading operation
      progressBar.Value = e.Index

      ' Check if we need to cancel (due to the user clicking the Cancel button)
      If cancelOperation Then
         e.Cancel = True
      End If
   End Sub

   Private Sub thumbnailBrowser_AddFile(ByVal sender As Object, ByVal e As RasterThumbnailBrowserAddFileEventArgs)
      Console.WriteLine("AddFile: {0} Add: {1} Total Pages: {2} Page:{3}", e.FileName, e.Add, e.TotalPages, e.Page)
   End Sub

   Private Sub thumbnailBrowser_FinishedLoadingThumbnails(ByVal sender As Object, ByVal e As EventArgs)
      buttonCancel.Enabled = False
   End Sub

   Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
      ' The user has clicked the cancel button
      Me.cancelOperation = True
   End Sub

   ' Create custom images to use as the "error" and "loading" thumbnails.
   Private Sub CreateErrorThumbnail()
      ' Get the image size
      Dim imageSize As Size = theBrowser.ItemImageSize

      ' No "loading" thumbnail
      theBrowser.LoadingThumbnail = Nothing

      ' For the "error" thumbnail, create a red X image
      Dim palette As RasterColor() = New RasterColor() {}
      Dim image As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, imageSize.Width, imageSize.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, palette, IntPtr.Zero, 0)

      Dim hdc As IntPtr = image.CreateLeadDC()
      Dim g As Graphics = Graphics.FromHdc(hdc)

      g.FillRectangle(Brushes.Magenta, 0, 0, imageSize.Width, imageSize.Height)

      g.DrawLine(Pens.Red, 0, 0, imageSize.Width, imageSize.Height)
      g.DrawLine(Pens.Red, imageSize.Width, 0, 0, imageSize.Height)

      g.Dispose()
      RasterImage.DeleteLeadDC(hdc)

      ' Make this image transparent
      image.Transparent = True
      image.TransparentColor = RasterColor.FromGdiPlusColor(Color.Magenta)

      theBrowser.ErrorThumbnail = image
   End Sub

   Public Sub Cleanup()
      RemoveHandler buttonBrowse.Click, AddressOf buttonBrowse_Click
      RemoveHandler buttonCancel.Click, AddressOf buttonCancel_Click
      RemoveHandler theBrowser.LoadThumbnail, AddressOf thumbnailBrowser_LoadThumbnail
      RemoveHandler theBrowser.FinishedLoadingThumbnails, AddressOf thumbnailBrowser_FinishedLoadingThumbnails
   End Sub

   Public Sub New()
      Size = New Size(300, 200)

      ' create the browser
      theBrowser = New RasterThumbnailBrowser()
      theBrowser.Codecs = New RasterCodecs()
      theBrowser.Dock = DockStyle.Fill
      theBrowser.ItemSpacingSize = New Size(10, 10)
      theBrowser.ThumbnailSizeFlags = RasterSizeFlags.Bicubic
      AddHandler theBrowser.LoadThumbnail, AddressOf thumbnailBrowser_LoadThumbnail
      AddHandler theBrowser.FinishedLoadingThumbnails, AddressOf thumbnailBrowser_FinishedLoadingThumbnails
      AddHandler theBrowser.AddFile, AddressOf thumbnailBrowser_AddFile

      ' Create a thumbnail image to be displayed on error
      CreateErrorThumbnail()

      ' add a panel
      Dim panel As Panel = New Panel()
      panel.Dock = DockStyle.Left
      panel.Width = 100
      Controls.Add(panel)
      panel.BringToFront()

      ' add a "browse" button
      buttonBrowse = New Button()
      buttonBrowse.Text = "Browse"
      buttonBrowse.Dock = DockStyle.Top
      panel.Controls.Add(buttonBrowse)
      AddHandler buttonBrowse.Click, AddressOf buttonBrowse_Click

      ' add a "cancel" button
      buttonCancel = New Button()
      buttonCancel.Text = "Cancel"
      buttonBrowse.Dock = DockStyle.Bottom
      panel.Controls.Add(buttonCancel)
      AddHandler buttonCancel.Click, AddressOf buttonCancel_Click

      ' add a progress bar
      progressBar = New ProgressBar()
      progressBar.Dock = DockStyle.Bottom
      Controls.Add(progressBar)

      Controls.Add(theBrowser)
      theBrowser.BringToFront()
   End Sub

   Private Sub InitializeComponent()
      Me.SuspendLayout()
      '
      ' MyForm
      '
      Me.ClientSize = New System.Drawing.Size(315, 273)
      Me.Name = "MyForm"
      Me.ResumeLayout(False)

   End Sub
End Class
Public Sub RasterThumbnailBrowser_RasterThumbnailBrowser()
   RasterCodecs.Startup()
   Dim form As MyForm = New MyForm()
   form.ShowDialog()
   form.Cleanup()
   RasterCodecs.Shutdown()
End Sub
C#Copy Code
class MyForm2 : Form 

   public RasterThumbnailBrowser theBrowser; 
   public bool cancelOperation;        // Informs us if the user canceled the operation 
   public Button buttonCancel;         // Cancel browse loading 
   public Button buttonBrowse;         // Diplays the browse control 
   public ProgressBar progressBar;     // shows progress of loading browse images 
   void buttonBrowse_Click(object sender, EventArgs e) 
   { 
      // If we are already loading thumbails, cancel 
      // this operation 
      if (theBrowser.IsLoadingThumbnails) 
         theBrowser.CancelLoadingThumbnails(); 
 
      // Clean all the items 
      theBrowser.Items.Clear(); 
 
      // Update the application state 
      buttonCancel.Enabled = true; 
      progressBar.Value = 0; 
 
      // And load the new thumbnails 
      cancelOperation = false; 
 
      string folderPath = LeadtoolsExamples.Common.ImagesPath.Path; 
      string[] files = new string[2] { folderPath + "\\image1.jpx", folderPath }; 
      theBrowser.LoadThumbnails(files, "*.jpg", RasterThumbnailBrowserLoadFlags.Block | RasterThumbnailBrowserLoadFlags.ExpandMultiPageFile); 
   } 
 
   private void thumbnailBrowser_LoadThumbnail(object sender, RasterThumbnailBrowserLoadThumbnailEventArgs e) 
   { 
      // If this is the first iteration, update the progress bar minimum and maximum values 
      if (e.Index == 0) 
      { 
         progressBar.Minimum = 0; 
         progressBar.Maximum = e.Total - 1; 
      } 
 
      // Update where we are in the loading operation 
      progressBar.Value = e.Index; 
 
      // Check if we need to cancel (due to the user clicking the Cancel button) 
      if (cancelOperation) 
         e.Cancel = true; 
   } 
 
   private void thumbnailBrowser_AddFile(object sender, RasterThumbnailBrowserAddFileEventArgs e) 
   { 
      Console.WriteLine("AddFile: {0}    Add: {1} Total Pages : {2} Page : {3}", e.FileName, e.Add, e.TotalPages, e.Page); 
   } 
 
   private void thumbnailBrowser_FinishedLoadingThumbnails(object sender, EventArgs e) 
   { 
      buttonCancel.Enabled = false; 
   } 
 
   private void buttonCancel_Click(object sender, EventArgs e) 
   { 
      // The user has clicked the cancel button 
      this.cancelOperation = true; 
   } 
 
   // Create  custom images to use as the "error" and "loading" thumbnails. 
   void CreateErrorThumbnail() 
   { 
      // Get the image size 
      Size imageSize = theBrowser.ItemImageSize; 
 
      // No "loading" thumbnail 
      theBrowser.LoadingThumbnail = null; 
 
      // For the "error" thumbnail, create a red X image 
      RasterColor[] palette = new RasterColor[0]; 
      RasterImage image = new RasterImage( 
         RasterMemoryFlags.Conventional, 
         imageSize.Width, 
         imageSize.Height, 
         24, 
         RasterByteOrder.Bgr, 
         RasterViewPerspective.TopLeft, 
      palette, 
      IntPtr.Zero, 
      0 
      ); 
 
      IntPtr hdc = image.CreateLeadDC(); 
      Graphics g = Graphics.FromHdc(hdc); 
 
      g.FillRectangle(Brushes.Magenta, 0, 0, imageSize.Width, imageSize.Height); 
 
      g.DrawLine(Pens.Red, 0, 0, imageSize.Width, imageSize.Height); 
      g.DrawLine(Pens.Red, imageSize.Width, 0, 0, imageSize.Height); 
 
      g.Dispose(); 
      RasterImage.DeleteLeadDC(hdc); 
 
      // Make this image transparent 
      image.Transparent = true; 
      image.TransparentColor = RasterColor.FromGdiPlusColor(Color.Magenta); 
 
      theBrowser.ErrorThumbnail = image; 
   } 
 
   public void Cleanup() 
   { 
      buttonBrowse.Click -= new EventHandler(buttonBrowse_Click); 
      buttonCancel.Click -= new EventHandler(buttonCancel_Click); 
      theBrowser.LoadThumbnail -= new EventHandler<RasterThumbnailBrowserLoadThumbnailEventArgs>(thumbnailBrowser_LoadThumbnail); 
      theBrowser.FinishedLoadingThumbnails -= new EventHandler(thumbnailBrowser_FinishedLoadingThumbnails); 
   } 
 
   public MyForm2() 
   { 
      Size = new Size(300, 200); 
 
      // create the browser 
      theBrowser = new RasterThumbnailBrowser(); 
      theBrowser.Codecs = new RasterCodecs(); 
      theBrowser.Dock = DockStyle.Fill; 
      theBrowser.ItemSpacingSize = new Size(10, 10); 
      theBrowser.ThumbnailSizeFlags = RasterSizeFlags.Bicubic; 
      theBrowser.LoadThumbnail += new EventHandler<RasterThumbnailBrowserLoadThumbnailEventArgs>(thumbnailBrowser_LoadThumbnail); 
      theBrowser.FinishedLoadingThumbnails += new EventHandler(thumbnailBrowser_FinishedLoadingThumbnails); 
      theBrowser.AddFile += new EventHandler<RasterThumbnailBrowserAddFileEventArgs>(thumbnailBrowser_AddFile); 
 
      // Create a thumbnail image to be displayed on error 
      CreateErrorThumbnail(); 
 
      // add a panel 
      Panel panel = new Panel(); 
      panel.Dock = DockStyle.Left; 
      panel.Width = 100; 
      Controls.Add(panel); 
      panel.BringToFront(); 
 
      // add a "browse" button 
      buttonBrowse = new Button(); 
      buttonBrowse.Text = "Browse"; 
      buttonBrowse.Dock = DockStyle.Top; 
      panel.Controls.Add(buttonBrowse); 
      buttonBrowse.Click += new EventHandler(buttonBrowse_Click); 
 
      // add a "cancel" button 
      buttonCancel = new Button(); 
      buttonCancel.Text = "Cancel"; 
      buttonBrowse.Dock = DockStyle.Bottom; 
      panel.Controls.Add(buttonCancel); 
      buttonCancel.Click += new EventHandler(buttonCancel_Click); 
 
      // add a progress bar 
      progressBar = new ProgressBar(); 
      progressBar.Dock = DockStyle.Bottom; 
      Controls.Add(progressBar); 
 
      Controls.Add(theBrowser); 
      theBrowser.BringToFront(); 
   } 
 
   private void InitializeComponent() 
   { 
      this.SuspendLayout(); 
      //  
      // MyForm 
      //  
      this.ClientSize = new System.Drawing.Size(315, 273); 
      this.Name = "MyForm"; 
      this.ResumeLayout(false); 
 
   } 

 
public void RasterThumbnailBrowser_LoadThumbnails2() 

   RasterCodecs.Startup(); 
   MyForm form = new MyForm(); 
   form.ShowDialog(); 
   form.Cleanup(); 
   RasterCodecs.Shutdown(); 
}

Remarks

Use the RasterThumbnailBrowser.LoadThumbnails(String,String,RasterThumbnailBrowserLoadFlags) method to populate the RasterThumbnailBrowser control with the thumbnails of image files found in the directory specified by path. The control will load the images in the following manner:

  • All items already in control are cleared.
  • The control will create an item for each file that matches searchPattern.
  • If RasterThumbnailBrowserLoadFlags.OnlyValidImageFiles is specified in flags, the control will use the GetInformation method of the RasterThumbnailBrowser.Codecs object to check if the given file contains a valid image or not. If it does not, no item will be created for this file.
  • The control fills the FileName property of the item with the name of the file found, Page will be set to 1, Text with file name and extension of the specified file and RasterImageListItem.Image with LoadingThumbnail. If RasterThumbnailBrowserLoadFlags.Block is specified in flags, the control will then continue to load the thumbnails for all items before returning. If RasterThumbnailBrowserLoadFlags.Block is not specified, the control will create a background thread to load the thumbnails for all the items and return control to the caller at this stage.
  • The control will raise the LoadThumbnail event for each item before it creates the thumbnail for it. You can use this event to update a progress bar, cancel the operation or load the thumbnail yourself.
  • If the non-blocking loading operation is specified, you can check the IsLoadingThumbnails at any time to determine whether the control has more items to load.
  • The FinishedLoadingThumbnails event is raised by the control when the thumbnails of all items have been created.
  • The CancelLoadingThumbnails method can be called at any time to abort creating the thumbnails of all items.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also